<script type="text/javascript" src="/js/jquery.ajaxfileupload.js"></script>
<div class="page_title"><h1 style="display: inline-block">${project.projectName}</h1>
    <#if project.classification == '0'>
        实例题
    <#else>
        设计题
    </#if>
</div>
<div class="panel panel-default">
    <div class="panel-header">
        作业详情
    </div>
    <div class="panel-body">
        <form class="form form-horizontal responsive" novalidate="novalidate">
            <div class="row cl">
                <label class="form-label col-xs-3">作业描述：</label>
                <div class="formControls col-xs-8">
                    <textarea class="textarea valid" placeholder="例：VB项目包含.vbp.frm.frx.bas文件，需压缩为zip文件上传"
                              id="expression"
                              autocomplete="off">${project.projectExpression}</textarea>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3">作业要求word上传：</label>
                <#--                带文本框-->
                <div class="formControls col-xs-8">
                <span class="btn-upload form-group">
                    <input class="input-text upload-url" type="text" name="docFileLoc" id="docFileLoc" readonly
                           placeholder="/Users/StupidZhe/IT/VB-T/VB03-T/VB03.doc"><a
                            href="javascript:void();" class="btn btn-primary"><i class="Hui-iconfont">&#xe6dc;</i> 浏览doc</a>
                    <input type="file" name="docFile" class="input-file" id="docFile">
                </span>
                    <#if project.docLocation?? && project.docLocation != ''>
                        <a href="/adm/project/file/?fileName=${project.docLocation}"><i
                                    class="Hui-iconfont">&#xe695;</i>下载</a>
                        <#else>
                            无附件
                    </#if>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3">作业要求上传：</label>
                <#--                带文本框-->
                <div class="formControls col-xs-8">
                <span class="btn-upload form-group">
                    <input class="input-text upload-url" type="text" name="demo" id="demo" readonly
                           placeholder="/Users/StupidZhe/IT/VB-T/VB03-T/prg1"><a
                            href="javascript:void();" class="btn btn-primary"><i class="Hui-iconfont">&#xe6dc;</i> 浏览文件</a>
                    <input type="file" name="projectFile" class="input-file" id="projectFile">
                </span>
                    <a href="/adm/project/file/?fileName=${project.demoLocation}"><i class="Hui-iconfont">&#xe695;</i>下载</a>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3">面向班级：</label>
                <div class="mt-5 formControls col-xs-8">
                    <#list classList as class>
                        <div class="check-box">
                            <#assign flag = false>
                            <#list pcList as pc>
                                <#if class.classNum == pc.classNum>
                                    <#assign flag = true>
                                    <input name="classCheck${class.classId}" type="checkbox" id="${class.classId}"
                                           checked="checked">
                                    <label for="${class.classId}">${class.classNum}</label>
                                </#if>
                            </#list>
                            <#if flag == false>
                                <input name="classCheck${class.classId}" type="checkbox" id="${class.classId}">
                                <label for="${class.classId}">${class.classNum}</label>
                            </#if>
                        </div>
                    </#list>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3">作业状态：</label>
                <div class="formControls col-xs-8">
                    <div class="mt-5 skin-minimal">
                        <#if project.status == "1">
                            <div class="radio-box">
                                <input type="radio" id="active" name="active" checked value="1">
                                <label for="active">激活</label>
                            </div>
                            <div class="radio-box">
                                <input type="radio" id="inactive" name="active" value="0">
                                <label for="inactive">失效</label>
                            </div>
                        <#else>
                            <div class="radio-box">
                                <input type="radio" id="active" name="active" value="1">
                                <label for="active">激活</label>
                            </div>
                            <div class="radio-box">
                                <input type="radio" id="inactive" name="active" checked value="0">
                                <label for="inactive">失效</label>
                            </div>
                        </#if>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3">学生最大上传次数：</label>
                <div class="formControls col-xs-8">
                    <input type="number" class="input-text valid" value="${project.upTimesMax}" id="upTimesMax"
                           autocomplete="off">
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-xs-offset-3">
                    <input id="addProjectBtn" class="btn btn-primary" type="button" value="&nbsp;&nbsp;修改&nbsp;&nbsp;">
                    <input class="btn btn-default" type="button" value="&nbsp;&nbsp;返回&nbsp;&nbsp;" onclick='selectView("/adm/project/", "作业管理")'>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    var docLocation = '${project.docLocation}';
    var demoLocation = '${project.demoLocation}';

    $("#addProjectBtn").on("click", function () {
        // stupidAjaxGetJson("")
    });
    $('#docFile').ajaxfileupload({
        action: '/adm/project/uploadDoc',
        valid_extensions: ['doc', 'docx', 'pdf', 'txt'],
        // valid_extensions: ['doc', 'docx','pdf','txt'],
        onStart: function () {
            layer.msg("正在上传中，请稍等", {icon: 4, shade: 0.5,time: 0});
            $("#docFileLoc").val($('#docFile').val());
        },
        onComplete: function (data) {
            setTimeout(function () {
                layer.closeAll();
                if (data.success) {
                    docLocation = data.msg;
                    layer.msg("上传成功", {time: 2000, icon: 1, shadeClose: true, shade: 0.5});
                } else {
                    if (data.msg !== undefined) {
                        layer.msg("上传失败：" + data.msg, {time: 0, shadeClose: true, icon: 2, shade: 0.5});
                    } else {
                        layer.msg("上传失败：不支持所上传的文档格式", {time: 0, shadeClose: true, icon: 2, shade: 0.5});
                    }
                }
            },1000);
        }
    });
    $('#projectFile').ajaxfileupload({
        action: '/adm/project/uploadProject',
        valid_extensions: ['zip'],
        // valid_extensions: ['doc', 'docx','pdf','txt'],
        onStart: function () {
            layer.msg("作业上传中，请稍等（由于需要进行编译，等待时间会因源程序差异而不同）", {icon: 4, shade: 0.5,time: 0});
            $("#demo").val($('#projectFile').val());
        },
        onComplete: function (data) {
            setTimeout(function () {
                layer.closeAll();
                if (data.success) {
                    demoLocation = data.msg;
                    layer.msg("上传成功", {time: 2000, icon: 1, shadeClose: true, shade: 0.5});
                } else {
                    $("#projectFile").val('');
                    if (data.msg !== undefined) {
                        layer.msg("上传失败：" + data.msg, {time: 0, shadeClose: true, icon: 2, shade: 0.5});
                    } else {
                        layer.msg("上传失败：仅支持zip文件", {time: 0, shadeClose: true, icon: 2, shade: 0.5});
                    }
                }
            }, 1000);
        }
    });
    $("#addProjectBtn").on("click", function () {
        var expression = $("#expression").val();
        var upTimesMax = $("#upTimesMax").val();
        if (demoLocation === null) {
            alert("作业样例不能为空");
            return;
        }
        var classArr = '';
        $(".check-box").children("input[type=checkbox]").each(function () {
            classArr += $(this).attr('id') + ":" + $(this).prop("checked") + ",";
        });

        var status = $("input[type='radio']:checked").val();
        stupidAjaxGetJson("/adm/project/${project.projectId}",
            "PUT",
            {
                expression: expression,
                demoLocation: demoLocation,
                docLocation: docLocation,
                classArr: classArr,
                status: status,
                upTimesMax: upTimesMax
            },
            function (data) {
                alert(data.msg);
                if (data.success) {
                    selectView("/adm/project/", "作业管理");
                }
            });
    });
</script>